﻿using System;
using cfg.Myskill;
using cfg.skill;
using Unity.VisualScripting;
using UnityEngine;

public class SkillBase
{
    protected string skillName;
    protected float skillTimer;//技能冷却时间
    protected float skillDuration;//技能持续时间
    protected bool canUseSkill;
    
    public bool skillDurationing;//技能发动中
    public bool isUnLock;//技能是否解锁
    
    public SkillBase(string skillName)
    {
       this.skillName = skillName; ;
    }
    public virtual void Update()
    {
        //技能持续期间不计算cd

        if (skillDuration<=0)
        {
            skillDurationing = false;
            if (skillTimer<=0)
            {
                canUseSkill = true;
            }
            else
            {
                skillTimer -= Time.deltaTime;
            }
            
        }
        else
        {
            skillDuration -= Time.deltaTime;
        }
    }

    public virtual void StopSkillDuration()
    {
        skillDuration = -1;
        skillDurationing = false;
    }

    public virtual bool CanUseSkill()
    {
        var  skillInfo = LoadCofigManager.Instance.GetSkillInfo(skillName).Info;
        if (canUseSkill)
        {
            skillTimer = skillInfo.SkillCd;
            skillDuration = skillInfo.SkillDuration;    
            canUseSkill = false;
            skillDurationing = true;
            Debuger.LogOrange(skillInfo.Name+"触发");
            return true;
        }
        else
        {
            Debuger.LogOrange(skillInfo.Name+"冷却中");
            return false;
        }
    }

    /*public virtual T GetSkillInfo<T>() where T : SkillInfoBase
    {
        if (skillInfo is T result)
        {
            return result;
        }
        throw new InvalidOperationException("SkillInfo is not of type " + typeof(T).Name);
    }*/


    public virtual void OnDestroy()
    {
        
    }
}